﻿<views:MvxWpfView
		xmlns:views="clr-namespace:Cirrious.MvvmCross.Wpf.Views;assembly=Cirrious.MvvmCross.Wpf"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
		xmlns:vms="clr-namespace:WebOptimizer.UI.ViewModels;assembly=WebOptimizer.UI"
		xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf"
		xmlns:local="clr-namespace:WebOptimizer.UI.Wpf.Views" x:Class="WebOptimizer.UI.Wpf.Views.TaskCollectionView"
		mc:Ignorable="d" 
		d:DesignHeight="500" d:DesignWidth="500">

	<views:MvxWpfView.Resources>
		<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
	</views:MvxWpfView.Resources>

	<Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:TaskCollectionViewModel}}" IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>

		<DataGrid Height="200" ItemsSource="{Binding ActiveEntity}" SelectedItem="{Binding ActiveTask}" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="False">
			<DataGrid.Columns>
				<DataGridCheckBoxColumn Binding="{Binding IsEnabled}" Header="Enabled" />
				<DataGridComboBoxColumn Header="Task Type" SelectedValueBinding="{Binding TaskTypeId}" SelectedValuePath="Value" DisplayMemberPath="Key" Width="150">
					<DataGridComboBoxColumn.ElementStyle>
						<Style TargetType="ComboBox">
							<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TaskCollectionView}}, Path=DataContext.TaskTypes}"/>
						</Style>
					</DataGridComboBoxColumn.ElementStyle>
					<DataGridComboBoxColumn.EditingElementStyle>
						<Style TargetType="ComboBox">
							<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:TaskCollectionView}}, Path=DataContext.TaskTypes}"/>
						</Style>
					</DataGridComboBoxColumn.EditingElementStyle>
				</DataGridComboBoxColumn>
				<DataGridTextColumn Binding="{Binding Path}" Header="Path" Width="*" SortDirection="Ascending" IsReadOnly="True"/>
			</DataGrid.Columns>
		</DataGrid>
		<Button Grid.Row="1" Command="{Binding AddTaskCommand}" Width="100" HorizontalAlignment="Left" Content="Add Task"/>

		<Grid Grid.Row="2" IsEnabled="{Binding CanEditTask, Mode=OneWay}">
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition />
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition />
			</Grid.ColumnDefinitions>

			<Label Content="Path:"/>
			<TextBox Grid.Column="1" Text="{Binding ActiveTask.Path}" />

			<DataGrid Height="100" Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding ActiveTask.Sources}" SelectedItem="{Binding ActiveSource}" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="False">
				<DataGrid.Columns>
					<DataGridCheckBoxColumn Binding="{Binding IsEnabled}" Header="Enabled"/>
					<DataGridCheckBoxColumn Binding="{Binding IncludeSubfolders}" Header="Subfolders" />
					<DataGridTextColumn Binding="{Binding Path}" Header="Path" Width="*" SortDirection="Ascending" IsReadOnly="True"/>
				</DataGrid.Columns>
			</DataGrid>
			<Button Grid.Row="3" Grid.ColumnSpan="2" Command="{Binding AddSourceCommand}" Width="100" HorizontalAlignment="Left" Content="Add Source"/>

			<Grid Grid.Row="4" Grid.ColumnSpan="2" IsEnabled="{Binding CanEditSource, Mode=OneWay}">
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition />
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<Label Content="Path:"/>
				<TextBox Grid.Column="1" Text="{Binding ActiveSource.Path}" />

				<Label Grid.Row="1" Content="Search Patterns:"/>
				<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ActiveSource.SearchPatterns}" />

				<Label Grid.Row="2" Content="Ignored Files:"/>
				<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding ActiveSource.IgnoredFiles}" />
			</Grid>
		</Grid>

		<StackPanel Grid.Row="3" Orientation="Horizontal">
			<Button Command="{Binding SaveCommand}" IsEnabled="{Binding IsSavable}" Width="100" Content="Save"/>
			<Button Command="{Binding LoadConfigurationCommand}" Width="100" Content="Load"/>
			<Button Command="{Binding ExecuteTaskCommand}" IsEnabled="{Binding CanEditTask, Mode=OneWay}" Width="100" Content="Execute"/>
			<Button Command="{Binding ExecuteAllTaskCommand}" Width="100" Content="Execute All Tasks"/>
		</StackPanel>
	</Grid>
</views:MvxWpfView>
